namespace Example.Models
{
    using System.Xml;
    using System.Xml.XPath;
    using SimpleWebServices;
    using SimpleWebServices.Globalization;
    using SimpleWebServices.Web;
    using Xunit;

    public sealed class GreetingFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<Greeting>()
                .DerivesFrom<Resource>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .XmlRoot("greeting")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            Greeting obj = (
                "<greeting>" +
                    "<data />" +
                    "<links />" +
                    "<metadata />" +
                    "<value>" +
                        "<translation xml:lang='en'>" +
                            "<string>Hello</string>" +
                        "</translation>" +
                        "<translation xml:lang='fr'>" +
                            "<string>Bonjour</string>" +
                        "</translation>" +
                    "</value>" +
                "</greeting>").Deserialize<Greeting>();

            Assert.Equal<string>("Hello", obj.Value["en"]);
            Assert.Equal<string>("Bonjour", obj.Value["fr"]);
        }

        [Fact]
        public void serialize()
        {
            Greeting obj = new Greeting
            {
                Value =
                {
                    { "en", "Hello" }
                }
            };

            XPathNavigator navigator = obj.Serialize().CreateNavigator();
            XmlNamespaceManager namespaces = new XmlNamespaceManager(navigator.NameTable);
            namespaces.AddNamespace("xml", "http://www.w3.org/XML/1998/namespace");

            Assert.True((bool)navigator.Evaluate("1=count(/greeting/value/translation[@xml:lang='en']/string[text()='Hello'])", namespaces));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new Greeting());
        }

        [Fact]
        public void prop_Value()
        {
            Assert.True(new PropertyExpectations(typeof(Greeting).GetProperty("Value"))
                .TypeIs<TranslationCollection<string>>()
                .DefaultValueIsNotNull()
                .Result);
        }
    }
}